import api from './index';

export interface LoginParams {
  username: string;
  password: string;
}

export interface RegisterParams {
  username: string;
  password: string;
  email: string;
  nickname?: string;
}

export interface UserInfo {
  id: string;
  username: string;
  nickname: string;
  email: string;
  avatar?: string;
  createdAt: string;
  updatedAt: string;
}

export interface AuthResponse {
  token: string;
  refreshToken: string;
  user: UserInfo;
}

// 用户登录
export const login = (params: LoginParams) => {
  return api.post<any, AuthResponse>('/auth/login', params);
};

// 用户注册
export const register = (params: RegisterParams) => {
  return api.post<any, AuthResponse>('/auth/register', params);
};

// 刷新令牌
export const refreshToken = (refreshToken: string) => {
  return api.post<any, { token: string }>('/auth/refresh-token', { refreshToken });
};

// 获取当前用户信息
export const getCurrentUser = () => {
  return api.get<any, UserInfo>('/auth/user');
};

// 用户登出
export const logout = () => {
  return api.post<any, void>('/auth/logout');
};